package com.xinxin.leetcode.problem504;

/**
 * @author ShiXinXin
 * @date 2020-01-10 9:03
 */
class Solution {
    public String convertToBase7(int num) {
        if (num < 7 && num > -7) {
            return num + "";
        }
        boolean sign = num < 0;
        num = num < 0 ? -num : num;
        StringBuilder res = new StringBuilder();
        while (num != 0) {
            res.insert(0, num % 7);
            num /= 7;
        }
        if (sign) {
            res.insert(0, "-");
        }
        return res.toString();
    }

    public static void main(String[] args) {
        System.out.println(new Solution().convertToBase7(100));
    }
}
